<template>
    <list :style="mainStyle">
        <cell>
            <user-head-item :itemValue="userInfo" ></user-head-item>
        </cell>
        <cell>
            <wxc-cell label="我的订单"
                      :has-arrow="true"
                      @wxcCellClicked="orderClick"
            ></wxc-cell>
            <wxc-cell label="我的作业"
                      :has-arrow="true"
                      @wxcCellClicked="TaskClick"
            ></wxc-cell>
        </cell>
        <cell>
            <wxc-cell label="个人信息"
                      :has-arrow="true"
                      @wxcCellClicked="SettingClick"
            ></wxc-cell>
        </cell>
    </list>
</template>

<script>
  import UserHeadItem from './widget/UserHeadItem.vue'
  import { getEntryPageStyle } from '../config/Config'
  import { Utils, WxcCell } from 'weex-ui'
  import user from '../core/net/user'

  export default {
    components: {
      WxcCell,
      UserHeadItem
    },
    data: () => {
      return {
        userData: {},
        mainStyle: {},
        webStyle: {height: '1334px', width: '750px'},
      }
    },
    methods: {
      orderClick () {
        this.jumpWithParams('CommonListPage', {
          userName: this.userInfo.ex.name,
          reposName: this.userInfo.ex.name,
          title: '我的订单',
          head: 'OrderHeadItem',
          dataType: 'userOrder',
        })
      },
      TaskClick () {
        this.jumpWithParams('CommonListPage', {
          userName: this.userInfo.ex.name,
          reposName: this.userInfo.ex.name,
          title: '我的作业',
          dataType: 'userTask',
        })
      },
      SettingClick () {
        this.jumpWithParams('SettingPage')
      },
      currentUserInfo () {
        // if (this.isMe === true) {
        //   return this.getUserInfo()
        // } else {
        //   return this.userData
        // }
        return this.userData
      },
      loadUserInfo () {
        user.getUserInfoDao().then((res) => {
          if (res && res.result) {
            this.userData = res.data
          }
        })
      },
    },
    created: function () {
      this.mainStyle = getEntryPageStyle(Utils)
      this.loadUserInfo()
    },
    activated: function () {
      if (WXEnvironment.platform === 'Web') {
        this.loadUserInfo()
      }
    },
    computed: {
      userInfo () {
        let userInfo = this.currentUserInfo()
        if (!userInfo) {
          return {ex: {}}
        }
        let ex = {
          userPic: userInfo.portrait,
          user: userInfo.login,
          name: userInfo.name ? userInfo.name : '---',
          courses: userInfo.course_number,
          tests: userInfo.test_number,
        }
        let user = {
          ex: ex,
        }
        return user
      },
    },
  }
</script>
